#include <bits/stdc++.h>
using namespace std;

/*

*/

/**
 * Your Bank object will be instantiated and called as such:
 * Bank* obj = new Bank(balance);
 * bool param_1 = obj->transfer(account1,account2,money);
 * bool param_2 = obj->deposit(account,money);
 * bool param_3 = obj->withdraw(account,money);
 */
// 法一
class Bank {
private:
    vector<long long> balances;  // 存储账户余额，索引0对应账户1，索引1对应账户2，以此类推
    int accountCount;            // 账户总数（n）
public:
    using ll = long long;
    Bank(vector<long long>& balance) {
        balances = balance;
        accountCount = balance.size();
    }
    
    bool transfer(int account1, int account2, long long money) {
        // 校验账户合法性（必须在1到accountCount之间）
        if (account1 < 1 || account1 > accountCount || account2 < 1 || account2 > accountCount) {
            return false;
        }
        // 校验金额合法性（必须为正数）
        if (money < 0) {
            return false;
        }
        // 校验转出账户余额是否充足
        int idx1 = account1 - 1;  // 转换为0-based索引
        if (balances[idx1] < money) {
            return false;
        }
        // 执行转账
        balances[idx1] -= money;
        balances[account2 - 1] += money;
        return true;
    }
    
    bool deposit(int account, long long money) {
        // 校验账户合法性
        if (account < 1 || account > accountCount) {
            return false;
        }
        // 校验金额合法性
        if (money < 0) {
            return false;
        }
        // 执行存款
        balances[account - 1] += money;
        return true;
    }
    
    bool withdraw(int account, long long money) {
        // 校验账户合法性
        if (account < 1 || account > accountCount) {
            return false;
        }
        // 校验金额合法性
        if (money < 0) {
            return false;
        }
        // 校验余额是否充足
        int idx = account - 1;
        if (balances[idx] < money) {
            return false;
        }
        // 执行取款
        balances[idx] -= money;
        return true;
    }
};

// 法一
class Bank {
public:
    vector <long long> m_balance;
    Bank(vector<long long>& balance) {
        m_balance = balance;
    }
    
    bool transfer(int account1, int account2, long long money) {
        if (((account1- 1) < 0 || (account2 - 1) < 0) || ((account1 - 1) >= m_balance.size() || (account2 - 1) >= m_balance.size())) {
            return false;
        }
        if(!withdraw(account1, money)) return false;
        if(!deposit(account2, money)) return false;
        return true;
    }
    
    bool deposit(int account, long long money) {
        if ((account - 1) < 0 || (account - 1) >= m_balance.size()) {
            return false;
        }
        m_balance[account - 1] += money;
        return  true;
    }
    
    bool withdraw(int account, long long money) {
        if ((account - 1)< 0 || (account - 1) >= m_balance.size()) {
            return false;
        }
        if (money >  m_balance[account -1 ]) {
            return false;
        }
        m_balance[account - 1] -= money;
        return true;
    }
};
